/*
WARNING: This SCRIPT USES SQL TEMPLATE PARAMETERS.
Be sure to hit CTRL+SHIFT+M in Query Analyzer 2005 or choose Specify Values for Template Parameters in Query Analyzer 2008 if running manually.
*/

DECLARE @BlogId uniqueidentifier
SET @BlogId = NewId()

/***  Insert initial Data ***/
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'administratorrole', 'Administrators');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'alternatefeedurl', '');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'authorname', 'My name');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'avatar', 'combine');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'blogrollmaxlength', '23');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'blogrollupdateminutes', '60');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'blogrollvisibleposts', '3');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'contactformmessage', '<p>I will answer the mail as soon as I can.</p>');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'contactthankmessage', '<h1>Thank you</h1><p>The message was sent.</p>');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'culture', 'Auto');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'dayscommentsareenabled', '0');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'description', 'Short description of the blog');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'displaycommentsonrecentposts', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'displayratingsonrecentposts', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'email', 'user@example.com');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'emailsubjectprefix', 'Weblog');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablecommentsearch', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablecommentsmoderation', 'False');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablecontactattachments', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablecountryincomments', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablehttpcompression', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enableopensearch', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablepingbackreceive', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablepingbacksend', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablerating', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablereferrertracking', 'False');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablerelatedposts', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enablessl', 'False');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enabletrackbackreceive', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'enabletrackbacksend', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'endorsement', 'http://www.dotnetblogengine.net/syndication.axd');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'fileextension', '.aspx');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'geocodinglatitude', '0');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'geocodinglongitude', '0');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'handlewwwsubdomain', '');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'iscocommentenabled', 'False');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'iscommentsenabled', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'language', 'en-GB');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'mobiletheme', 'Mobile');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'name', 'Name of the blog');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'numberofrecentcomments', '10');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'numberofrecentposts', '10');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'postsperfeed', '10');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'postsperpage', '10');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'removewhitespaceinstylesheets', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'searchbuttontext', 'Search');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'searchcommentlabeltext', 'Include comments in search');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'searchdefaulttext', 'Enter search term');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'sendmailoncomment', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'showdescriptioninpostlist', 'False');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'showlivepreview', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'showpostnavigation', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'smtppassword', 'password');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'smtpserver', 'mail.example.dk');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'smtpserverport', '25');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'smtpusername', 'user@example.com');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'storagelocation', '~/App_Data/');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'syndicationformat', 'Rss');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'theme', 'Standard');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'timestamppostlinks', 'True');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'timezone', '-5');
INSERT INTO <tablePrefix,varchar(15),be_>Settings (BlogId, SettingName, SettingValue)	VALUES (@BlogId, 'trackingscript', '');

DECLARE @postID uniqueidentifier, @catID uniqueidentifier;

SET @postID = NEWID();
SET @catID = NEWID();

INSERT INTO <tablePrefix,varchar(15),be_>Categories (CategoryID, CategoryName)
	VALUES (@catID, 'General');

INSERT INTO <tablePrefix,varchar(15),be_>Posts (PostID, Title, Description, PostContent, DateCreated, Author, IsPublished)
	VALUES (@postID, 
	'Welcome to BlogEngine.NET 1.4.5 using Microsoft SQL Server', 
	'The description is used as the meta description as well as shown in the related posts. It is recommended that you write a description, but not mandatory',
	'<p>If you see this post it means that BlogEngine.NET 1.4.5 is running with SQL Server and the DbBlogProvider is configured correctly.</p>
	<h2>Setup</h2>
	it is time to setup some users.  Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.</p
	<h2>Write permissions</h2>
	if you want to store attachments or images in the blog, you will want write permissions setup on the App_Data folder.</p
	<h2>On the web </h2>
	tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at <a href="http://www.codeplex.com/blogengine"CodePlex</a> where the daily builds will be published for anyone to download.</p>
	<p>Good luck and happy writing.</p>
	<p>The BlogEngine.NET team</p>',
	GETDATE(), 
	'admin',
	1);

INSERT INTO <tablePrefix,varchar(15),be_>PostCategory (PostID, CategoryID)
	VALUES (@postID, @catID);
INSERT INTO <tablePrefix,varchar(15),be_>PostTag (PostID, Tag)
	VALUES (@postID, 'blog');
INSERT INTO <tablePrefix,varchar(15),be_>PostTag (PostID, Tag)
	VALUES (@postID, 'welcome');

INSERT INTO <tablePrefix,varchar(15),be_>Users (UserName, Password, LastLoginTime, EmailAddress)
	VALUES ('Admin', '', GETDATE(), 'email@example.com');
INSERT INTO <tablePrefix,varchar(15),be_>Roles (Role) 
	VALUES ('Administrators');
INSERT INTO <tablePrefix,varchar(15),be_>Roles (Role) 
	VALUES ('Editors');

INSERT INTO [dbo].[<tablePrefix,varchar(15),be_>Blogs]
           ([BlogId], [Host], [Path], [Port])
     VALUES
           (@BlogId, <blogHost,varchar(100),'localhost'>, <blogPath, varchar(255),NULL>, <blogPort, int, NULL>)

INSERT INTO [dbo].[<tablePrefix,varchar(15),be_>BlogCategories]
	SELECT @BlogId, CategoryID FROM [dbo].[<tablePrefix,varchar(15),be_>Categories]
	WHERE NOT CategoryID IN (SELECT CategoryID FROM [<tablePrefix,varchar(15),be_>BlogCategories])

INSERT INTO [dbo].[<tablePrefix,varchar(15),be_>BlogPosts]
	SELECT @BlogId, PostID FROM [dbo].[<tablePrefix,varchar(15),be_>Posts]
	WHERE NOT PostID IN (SELECT PostId FROM [<tablePrefix,varchar(15),be_>BlogPosts])

INSERT INTO [dbo].[<tablePrefix,varchar(15),be_>BlogRoles]
	SELECT @BlogId, RoleID FROM [dbo].[<tablePrefix,varchar(15),be_>Roles]
	WHERE NOT RoleID IN (SELECT RoleId FROM [<tablePrefix,varchar(15),be_>BlogRoles])

INSERT INTO [dbo].[<tablePrefix,varchar(15),be_>BlogUsers]
	SELECT @BlogId, UserID FROM [dbo].[<tablePrefix,varchar(15),be_>Users]
	WHERE NOT UserID IN (SELECT UserId FROM [<tablePrefix,varchar(15),be_>BlogUsers])

DECLARE @UserId int,
	@RoleId int

SELECT @UserId = u.UserId FROM <tablePrefix,varchar(15),be_>Users u
JOIN <tablePrefix,varchar(15),be_>BlogUsers bu ON u.UserId = bu.UserId
WHERE bu.BlogId = @BlogId AND u.UserName = 'Admin'

SELECT @RoleId = r.RoleId FROM <tablePrefix,varchar(15),be_>Roles r
JOIN <tablePrefix,varchar(15),be_>BlogRoles br ON r.RoleId = br.RoleId
WHERE br.BlogId = @BlogId AND r.Role = 'Administrators'

INSERT INTO <tablePrefix,varchar(15),be_>UserRoles (UserID, RoleID)
VALUES (@UserId, @RoleId);